fix name escaping issue in Cargo.toml (#1635) and added corresponding
authorRoy van der Vegt "platypus <royvandervegt@gmail.com>
Mon, 25 May 2015 14:49:10 +0000 (16:49 +0200)
committerRoy van der Vegt <royvandervegt@gmail.com>
Tue, 26 May 2015 19:42:10 +0000 (21:42 +0200)
test

src/cargo/ops/cargo_new.rs
tests/test_cargo_new.rs

index 217823c2b6b31f390e9c6fcdd28cf5c41b007b5d..3f032b4fad975bba2d1b18a3f63b22b92cb9a01e 100644 (file)
@@ -13,6 +13,8 @@ use term::color::BLACK;
 use util::{GitRepo, HgRepo, CargoResult, human, ChainError, internal};
 use util::Config;
 
+use toml;
+
 #[derive(Clone, Copy, Debug, PartialEq)]
 pub enum VersionControl { Git, Hg, NoVcs }
 
@@ -149,8 +151,8 @@ fn mk(config: &Config, path: &Path, name: &str,
 r#"[package]
 name = "{}"
 version = "0.1.0"
-authors = ["{}"]
-"#, name, author).as_bytes()));
+authors = [{}]
+"#, name, toml::Value::String(author)).as_bytes()));
 
     try!(fs::create_dir(&path.join("src")));
 
index 6a7b82c7749fdabbaec02f4f456f3cf2aea3a94d..c315afb2f7579a35fc14bfd824ad725dd1fb89e7 100644 (file)
@@ -138,6 +138,20 @@ test!(finds_author_user {
     assert!(contents.contains(r#"authors = ["foo"]"#));
 });
 
+test!(finds_author_user_escaped {
+    // Use a temp dir to make sure we don't pick up .cargo/config somewhere in
+    // the hierarchy
+    let td = TempDir::new("cargo").unwrap();
+    assert_that(cargo_process("new").arg("foo").env("USER", "foo \"bar\"")
+                                    .cwd(td.path().clone()),
+                execs().with_status(0));
+
+    let toml = td.path().join("foo/Cargo.toml");
+    let mut contents = String::new();
+    File::open(&toml).unwrap().read_to_string(&mut contents).unwrap();
+    assert!(contents.contains(r#"authors = ["foo \"bar\""]"#));
+});
+
 test!(finds_author_username {
     // Use a temp dir to make sure we don't pick up .cargo/config somewhere in
     // the hierarchy